package com.itheima.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.api.SmsHomeRecommendSubjectApi;
import com.itheima.pojo.SmsHomeRecommendSubject;
import com.itheima.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Hakuna Matata
 * @date 2022-10-13-15:46
 */
@Service
public class SmsHomeRecommendSubjectService {

    @DubboReference
    private SmsHomeRecommendSubjectApi recommendSubjectApi;

    //添加首页推荐专题
    public void create(SmsHomeRecommendSubject recommendSubject) {
        recommendSubjectApi.create(recommendSubject);
    }

    //批量删除推荐
    public void delete(Integer[] ids) {
        if (ids != null && ids.length > 0) {
            for (Integer id : ids) {
                recommendSubjectApi.delete(id);
            }
        }
    }

    //分页查询推荐
    public PageResult list(Integer pageNum, Integer pageSize, String subjectName, Integer recommendStatus) {
        return recommendSubjectApi.list(pageNum, pageSize, subjectName, recommendStatus);
    }

    //批量修改推荐状态
    public void updateStatus(Integer[] ids, Integer recommendStatus) {
        if (ids != null && ids.length > 0) {
            for (Integer id : ids) {
                recommendSubjectApi.updateStatus(Convert.toLong(id), recommendStatus);
            }
        }
    }

    //修改推荐排序
    public void updateSortId(Long id, Integer sort) {
        recommendSubjectApi.updateSortId(id, sort);
    }
}
